﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace xml_tu_003
{
    public partial class Form1 : Form
    {
        DataTable m_data_table;

        public Form1()
        {
            InitializeComponent();

            // initialize data member
            m_data_table = new DataTable();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataSet data_set = new DataSet();
            m_data_table.Columns.Add(new DataColumn("Product_ID", Type.GetType("System.Int32")));
            m_data_table.Columns.Add(new DataColumn("Product_Name", Type.GetType("System.String")));
            m_data_table.Columns.Add(new DataColumn("Product_Price", Type.GetType("System.Int32")));

            fillRows(1, "Product1", 11111);
            fillRows(2, "Product2", 22222);
            fillRows(3, "product3", 33333);
            fillRows(4, "product4", 44444);

            data_set.Tables.Add(m_data_table);
            data_set.Tables[0].TableName = "product";
            data_set.WriteXml("product.xml");
            MessageBox.Show("Done");
        }

        private void fillRows(int pID, string pName, int pPrice)
        {
            DataRow data_row;
            data_row = m_data_table.NewRow();
            data_row["Product_ID"] = pID;
            data_row["Product_Name"] = pName;
            data_row["Product_Price"] = pPrice;
            m_data_table.Rows.Add(data_row);

        }
    }
}
